package com.example.hanchen.yongkanggy.http;

import java.util.concurrent.TimeUnit;

import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.logging.HttpLoggingInterceptor;

public class OkUtils {

    private OkHttpClient okHttpClient;

    public OkUtils() {
        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        okHttpClient = new OkHttpClient.Builder()
                .connectTimeout(20, TimeUnit.SECONDS)
                .readTimeout(20, TimeUnit.SECONDS)
//                .callTimeout(20, TimeUnit.SECONDS)
                .addInterceptor(loggingInterceptor)
                .build();
    }

    public static OkUtils getInstance() {
        return OkHolder.okUtils;
    }

    static class OkHolder {
        private static final OkUtils okUtils = new OkUtils();
    }


    public void getindivAuthUrl(Callback callback) {
//        StringBuffer sburl = new StringBuffer();
//        sburl.append("http://192.168.0.2:8111/eqb/psnAuthUrl").append("?")
//                .append("phone=").append("18813005884");
//        Request request = new Request.Builder()
//                .url(sburl.toString()).build();
//        okHttpClient.newCall(request).enqueue(callback);


        FormBody.Builder builder = new FormBody.Builder();
        builder.add("phone", "18813005884");
        FormBody body = builder.build();

        Request request = new Request.Builder()
                .post(body)
                .url("http://192.168.0.2:8111/eqb/psnAuthUrl")
                .build();
        okHttpClient.newCall(request).enqueue(callback);
    }


}
